a = 6662

while a != 6174 and len(set(str(a)))>1:
    little = (sorted(list(str(a))))
    big = (sorted(list(str(a)), reverse=True))

    little = int(''.join(little))
    big = int(''.join(big))
    a = big-little
    print(a)
